const express = require('express');
const bodyParser = require("body-parser");

const app = express();

const port = 3000;

const allowCrossDomain = function (req, res, next) {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
    res.header('Access-Control-Allow-Headers', 'Content-Type,Authorization,X-Requested-With');
    res.header('Access-Control-Allow-Credentials', "true");
    next();
};

app.use(bodyParser.json());
app.use(allowCrossDomain);

app.get('/ping', (req, res) => {
    res.end('pong');
 });

app.post('/login', (req, res) =>{
    let data = {"retCode":"00","retMsg":"OK","data":{"name":"user01","address":"0xffff00000000000000000000000000000000ff01","sessionid":"8PdO8wQsAiW5oPHsr9tB8yk_LT47CYNP","BTC":799.921,"ETH":801,"BTCAddress":"0xceb50db76221420f8720ed46e25ba06c","ETHAddress":"0x7b14ea96a534467aa60902b9cb3998a2","BTCLocked":0,"ETHLocked":0}};
    res.end(JSON.stringify(data));
})

app.post('/userqueryCoinAddr', (req, res) => {
    let data = {"retCode":"00","retMsg":"OK","data":{"BTC":800,"ETH":799,"BTCAddress":"0xceb50db76221420f8720ed46e25ba06c","ETHAddress":"0x7b14ea96a534467aa60902b9cb3998a2","BTCLocked":0,"ETHLocked":1}}
    res.end(JSON.stringify(data));
})


app.post('/bsList', (req, res) => {
    let data = {"retCode":"00","retMsg":"OK","data":{"bsList":[{},{"orderid":"806386000007","sysOrderid":"0","dt":"2018-06-26 02:58:58","name":"ETH/BTC","type":"sell","price":0.079,"no":1,"noFilled":0,"state":1}]}};
    res.end(JSON.stringify(data));
})

app.post('/userBuy', (req, res) => {
    let data = {"retCode":"00","retMsg":"å·²æˆäº¤","data":{}};
    res.end(JSON.stringify(data));
})

app.listen(port, () => {
    console.log('app now listening on port: ', port);
})